package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocCreditPromptDao;
import com.irdstudio.cdp.pboc.service.domain.PbocCreditPrompt;
import com.irdstudio.cdp.pboc.service.facade.PbocCreditPromptService;
import com.irdstudio.cdp.pboc.service.vo.PbocCreditPromptVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 信用提示信息				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocCreditPromptService")
public class PbocCreditPromptServiceImpl implements PbocCreditPromptService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocCreditPromptServiceImpl.class);

	@Autowired
	private PbocCreditPromptDao pbocCreditPromptDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocCreditPrompt(PbocCreditPromptVO inPbocCreditPromptVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocCreditPromptVo.toString());
		int num = 0;
		try {
			PbocCreditPrompt pbocCreditPrompt = new PbocCreditPrompt();
			beanCopy(inPbocCreditPromptVo, pbocCreditPrompt);
			num = pbocCreditPromptDao.insertPbocCreditPrompt(pbocCreditPrompt);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocCreditPromptVO inPbocCreditPromptVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocCreditPromptVo);
		int num = 0;
		try {
			PbocCreditPrompt pbocCreditPrompt = new PbocCreditPrompt();
			beanCopy(inPbocCreditPromptVo, pbocCreditPrompt);
			num = pbocCreditPromptDao.deleteByPk(pbocCreditPrompt);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditPromptVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocCreditPromptVO inPbocCreditPromptVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocCreditPromptVo.toString());
		int num = 0;
		try {
			PbocCreditPrompt pbocCreditPrompt = new PbocCreditPrompt();
			beanCopy(inPbocCreditPromptVo, pbocCreditPrompt);
			num = pbocCreditPromptDao.updateByPk(pbocCreditPrompt);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditPromptVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocCreditPromptVO queryByPk(PbocCreditPromptVO inPbocCreditPromptVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocCreditPromptVo);
		try {
			PbocCreditPrompt queryPbocCreditPrompt = new PbocCreditPrompt();
			beanCopy(inPbocCreditPromptVo, queryPbocCreditPrompt);
			PbocCreditPrompt queryRslPbocCreditPrompt = pbocCreditPromptDao.queryByPk(queryPbocCreditPrompt);
			if (Objects.nonNull(queryRslPbocCreditPrompt)) {
				PbocCreditPromptVO outPbocCreditPromptVo = beanCopy(queryRslPbocCreditPrompt, new PbocCreditPromptVO());
				logger.debug("当前查询结果为:"+ outPbocCreditPromptVo.toString());
				return outPbocCreditPromptVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditPromptVO> queryAllOwner(PbocCreditPromptVO pbocCreditPromptVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocCreditPromptVO> list = null;
		try {
			List<PbocCreditPrompt> pbocCreditPrompts = pbocCreditPromptDao.queryAllOwnerByPage(pbocCreditPromptVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocCreditPrompts.size());
			pageSet(pbocCreditPrompts, pbocCreditPromptVo);
			list = (List<PbocCreditPromptVO>) beansCopy(pbocCreditPrompts, PbocCreditPromptVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditPromptVO> queryAllCurrOrg(PbocCreditPromptVO pbocCreditPromptVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocCreditPrompt> pbocCreditPrompts = pbocCreditPromptDao.queryAllCurrOrgByPage(pbocCreditPromptVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocCreditPrompts.size());
		List<PbocCreditPromptVO> list = null;
		try {
			pageSet(pbocCreditPrompts, pbocCreditPromptVo);
			list = (List<PbocCreditPromptVO>) beansCopy(pbocCreditPrompts, PbocCreditPromptVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditPromptVO> queryAllCurrDownOrg(PbocCreditPromptVO pbocCreditPromptVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocCreditPrompt> pbocCreditPrompts = pbocCreditPromptDao.queryAllCurrDownOrgByPage(pbocCreditPromptVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocCreditPrompts.size());
		List<PbocCreditPromptVO> list = null;
		try {
			pageSet(pbocCreditPrompts, pbocCreditPromptVo);
			list = (List<PbocCreditPromptVO>) beansCopy(pbocCreditPrompts, PbocCreditPromptVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
